<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../res/css/common/font-awesome.min.css" media="all">
		<link rel="stylesheet" href="../../../res/layui-config/css/app.css" media="all">
		<title>总店总经理审核</title>
	</head>
	<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  		<legend>总店总经理审核</legend>
	</fieldset>
		<div class="kit-table">
				<!-- 操作按钮 -->
		    <div class="kit-table-body">
		        <table id="demo" lay-filter="demo"></table>
		        <script type="text/html" id="barDemo">
		            <button class="layui-btn layui-btn-xs" lay-event="edit">查看订单详情</button>
		            <button class="layui-btn layui-btn-xs" lay-event="detail">审核</button>
		        </script>
		    </div>
		</div>
		
		<!-- 修改页面 -->
		<script type="text/html" id="edit-tpl">
		    <div style="margin:10px">
		        <form class="layui-form" action="" lay-filter="form-edit">
		           <input type="hidden" value="{{d.rowdata.audId}}" name="audId"/>
					<input type="hidden" value="{{d.rowdata.audFkId}}" name="audFkId"/>
					<div class="layui-form-item">
						<label class="layui-form-label">审核部门</label>
						<div class="layui-input-block">
							<input type="text" name="user" value="总店总经理审核" id="user" lay-verify="title" disabled="disabled" autocomplete="off" placeholder="请输入标题" class="layui-input">
						</div>
					</div>
				<div class="layui-form-item">
					<label class="layui-form-label">订单时间</label>
					<div class="layui-input-block">
						<input type="text" value="{{d.rowdata.audTimes}}" lay-verify="title" placeholder="" disabled="disabled" autocomplete="off" class="layui-input">
					</div>
				</div>
  
  
				<div class="layui-form-item">
					<label class="layui-form-label">是否通过</label>
					<div class="layui-input-block">
						<input type="radio" name="audState" id="audState1" title="是" checked="checked" value="16" >
						<input type="radio" name="audState" id="audState2" title="否" value="15">
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">审核意见</label>
					<div class="layui-input-block">
						<textarea placeholder="请输入内容" id="audMes" name="audMes" required lay-verify="required" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formEdit2">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
		        </form>
		    </div>
		</script>
		
		<!-- 显示表格 -->
		<script src="../../../res/layui/layui.js"></script>
		<script>
		    layui.use(['table'], function() {
		        var table = layui.table,
		            $ = layui.jquery,
		            layer = layui.layer,
		            form = layui.form,
		            laytpl = layui.laytpl;
		        var tableIns = table.render({
		            elem: '#demo',
		            height: 'full-50', //容器高度
		            url: '../../../audit/findCEO.action',
		            page: true,
		            id: 'demo',
		            cols: [
		            	 [{field: 'audId',title: 'ID', width: 273},
				        {field: 'audFkId',title: '单号',width: 175},
		                {field: 'comparyName',title: '厂家',width: 80},
		                {field: 'audStates',title: '审核状态',width: 200},
		                {field: 'audIdea',title: '审核意见',width: 150},
		                {field: 'audName',title: '审核人',width: 90},
		                {fixed: 'right',title: '操作',width: 220,align: 'center', toolbar: '#barDemo' }]
		            ],
		            done: function(res, curr, count) {
		            	var tableElem = this.elem.next('.layui-table-view');
		            	$("[data-field = 'audId']").children().not(":first").each(function(index){
			            	var url = "../../../audit/findById.action";  
			            	var data = {"audId":$(this).text()};	
			            	$.post(url,data,function(mes){
			            		if(mes.audState==15||mes.audState==16){
			            			tableElem.find('tr[data-index="'+ index +'"]').find('button[lay-event=detail]').addClass('layui-btn-disabled').attr('disabled',true);
					            	
			            		}
			            		
		            		},"json");
					  	});
		            	$("[data-field = 'audStates']").children().not(":first").each(function(index){
			            	if($(this).text()=="审核失败"){
			            		$(this).html("<font style='color:red;'>审核未通过</font>");
			            	}
					  	});
		            },
		            loading: true,
		            //method: 'post'
		        });
						//城市及角色
		        var staticData = {
		            citys: [{id: 0,name: '北京'},
		            	{id: 1,name: '广州'}, 
		            	{id: 2,name: '深圳'}, 
		            	{id: 3,name: '杭州'}],
		            classifies: [{id: 0,name: '词人' }, 
		            	{id: 1,name: '诗人'}, 
		            	{id: 2,name: '作家'}, 
		            	{id: 3,name: '酱油'}]
		        };
		        //监听搜索表单提交
		        form.on('submit(search)', function(data) {
		            console.log(data.field);
		            layer.msg(JSON.stringify(data.field));
		            //带条件查询
		            tableIns.reload({
		                where: data.field
		            });
		            return false;
		        });
		        //监听工具条
		        table.on('tool(demo)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		            var data = obj.data; //获得当前行数据
		            var layEvent = obj.event; //获得 lay-event 对应的值
		            var tr = obj.tr; //获得当前行 tr 的DOM对象
		
		            if (layEvent === 'detail') { //审核
		            	console.log(data);
	            		var d = {
	            				rowdata: data
			                };
	            		showlayer(d);
		            } else if (layEvent === 'del') { //不审核
		            } else if (layEvent === 'edit') { //查看详情
		            	layer.open({
                            type: 2,
                            title: '信息',
                            content:['../../branchBuy/findDetail.html?id='+data.audFkId, 'no'],
                            area: ['920px', '450px'],
                            yes: function(index, layero) {
                                editIndex = index;
                                $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
                            },
                            btn2: function(index, layero) {
                                $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
                                return false;
                            },
                            success: function() {
                                form.render(null, 'form-edit');
                            }
                        });
		            }
		        });
		        form.render(null, 'kit-search-form');
		        $('#kit-search-more').on('click', function() {
		            $('.kit-search-mored').toggle();
		        });
		        var editIndex;
		        form.on('submit(formEdit)', function(data) {
		            layer.msg('formEdit');
		            editIndex && layer.close(editIndex); //关闭弹出层
		            return false;
		        });
		        
		        
		    	//说明书增加和修改弹出层   提交按钮点击事件
		        form.on('submit(formEdit2)', function(data) {
		        	var cls = update("../../../audit/auditByaudId.action",data.field);
                	if (cls) editIndex2 && layer.close(editIndex2); //关闭弹出层
                	layerIFrameReload(layerIndex2);
                	return false;
		        });
		        
		        function update(url,data){
			    	var cls = false;
			    	$.ajax({
			    		url: url,
	                    type:'post',//method请求方式，get或者post
	                    async:false,//同步
	                    dataType:'json',//预期服务器返回的数据类型
	                    data: JSON.stringify(data),//表格数据序列化
	                    contentType: "application/json; charset=utf-8",
	                    success:function(mes){//res为相应体,function为回调函数
	                    	$(".layui-laypage-btn")[0].click();//当前表格刷新
	                        if(mes.status==1){ 
	                        	cls = true;//有弹出层时是关闭弹出层 false不关闭
		                        $("#res").click();//调用重置按钮将表单数据清空
	                        }
	                        layer.msg(mes.msg);
	                    },
	                   	error:function(){layer.alert('数据异常，请稍后重试！！！',{icon:5});}
	                 });
			    	return cls;
			    }
		        
		      //渲染 修改和增加弹出层
			   function showlayer(d){
			    	laytpl($('#edit-tpl').html()).render(d,function(html) {
	                    layer.open({
	                        type: 1,
	                        title: '表单',
	                        content: html,
	                        area: ['600px', '500px'],
	                        yes: function(index, layero) {
	                            editIndex = index;
	                            $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
	                        },
	                        btn2: function(index, layero) {
	                            $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
	                            return false;
	                        },
	                        success: function() {
	                            form.render(null, 'form-edit');
	                        }
	                    });
	                });
			    }
		        $('.kit-search-btns').children('a').off('click').on('click', function() {
		            var $that = $(this),
		                action = $that.data('action');
		            switch (action) {
		                case 'add':
		                    var d = {
		                        user: {
		                            sign: '你哈',
		                            city: '',
		                            classify: '',
		                            experience: '',
		                            id: 0,
		                            logins: '',
		                            score: '',
		                            sex: 1,
		                            sign: '',
		                            username: '',
		                            wealth: ''
		                        },
		                        citys: staticData.citys,
		                        classifies: staticData.classifies
		                    };
		                    break;
		                case 'del-bulk':
		                    var d = table.checkStatus('demo');
		                    if (d.data.length === 0) {
		                        layer.msg('请选择要删除的数据');
		                        return;
		                    }
		                    var data = d.data,
		                        names = [],
		                        ids = [];
		                    layui.each(data, function(index, item) {
		                        console.log(item);
		                        names.push(item.username);
		                        ids.push(item.id);
		                    });
		                    layer.msg(names.join(','));
		                    console.log(ids.join(','));
		                    break;
		            }
		        });
		    });
		</script>
	</body>
</html>
